const {database} = require("@common/config");

class chatServer {
  async getChatList(){
    try {
      const statement = `SELECT * FROM wx_chat_list`
      const [result] = await database.promise().execute(statement)
      return result
    } catch (err) {
      throw new Error(err)
    }
  }

  async getChatMessage(userId,friendId){
    try {
      const statement = `
      SELECT * FROM wx_chat_message where (user_id = ? && friend_id = ?) || (user_id = ? && friend_id = ?) ORDER BY createAt`
      const [result] = await database.promise().execute(statement,[userId,friendId,friendId,userId])
      return result
    } catch (err) {
      throw new Error(err)
    }
  }


}

module.exports = new chatServer()